//
//  ZPMainViewController.swift
//  weibo
//
//  Created by zhangpeng on 16/4/16.
//  Copyright © 2016年 zhangpeng. All rights reserved.
//

import UIKit

class ZPMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //初始化tabBar
        let tabBar = ZPTabBar()
        
        tabBar.zpDelegate = self
        
        // self.tabBar  系统私有属性 不能直接设置
        // 通过kvc
        setValue(tabBar, forKey: "tabBar")
        
        //创建子添加控制器
       
        addChildViewController(ZPHomeTController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(ZPMessageTController(), imgName: "tabbar_message_center", title: "消息")
        addChildViewController(ZPDiscoverTController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(ZPProfileTController(), imgName: "tabbar_profile", title: "我的")
        
        
    }
    
     func addChildViewController(childController: UIViewController , imgName:String , title:String ) {
        
        childController.tabBarItem.image = UIImage(named: imgName)
        
        childController.title = title
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
         addChildViewController(UINavigationController(rootViewController: childController))
    }
}

// MARK: - CZTabBarDelegate
// extension 相当于我们OC中的分类 extension 后面的类 CZMainViewController 就代表是当前类的分类
extension ZPMainViewController:ZPTabBarDelegate{
 
    func composeButtonClick() {
        print("点击按钮了")
    }
}
